//
//  main.swift
//  9.字面量表达
//
//  Created by 左忠飞 on 2021/8/12.
//

import Foundation

//通过字符串字面量初始化一个自定义类型

//符合ExpressibleByStringLiteral协议
//实现协议中的三个方法
class Person:ExpressibleByStringLiteral {
    let name:String
    
    init(name:String){
        self.name = name
    }
    
    required convenience init(stringLiteral value: StringLiteralType) {
        self.init(name: value)
    }
    required convenience init(unicodeScalarLiteral value: String) {
        self.init(name: value)
    }
    required convenience init(extendedGraphemeClusterLiteral value: String) {
        self.init(name: value)
    }
}

//直接用字面量创建对应的对象
let xiaoming:Person = "小明"
print(xiaoming.name)

